--
-- $Id: stdlib.lua 9ce65bed8ef4 2012/08/26 02:14:51 pgurumur $
-- Copyright (c) 2012 Prabhu Gurumurthy <pgurumur@gmail.com>
--
-- Permission to use, copy, modify, and distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--

-- __version__  = "$Revision: 9ce65bed8ef4 $"
-- __author__   = "$Author: pgurumur $"
-- __modified__ = "$Date: 2012-08-26 02:14:51Z $"
#!/usr/bin/env lua

printf = function(str, ...)
   io.write(str:format(...))
end

ip = {}
ip.__index = ip

function ip:init(Address)
   local _ip = {}
   setmetatable(_ip, ip)
end

function GetTableLength(table)
   local index = 0
   for kyes in pairs(Table) do
      if keys >= 0 then
         index = index + 1
      end
   end

   return index
end

-- Compatibility: Lua-5.0
function split(str, delim, maxNb)
    -- Eliminate bad cases...
    if string.find(str, delim) == nil then
        return { str }
    end
    if maxNb == nil or maxNb < 1 then
        maxNb = 0    -- No limit
    end
    local result = {}
    local pat = "(.-)%" .. delim .. "()"
    local nb = 0
    local lastPos
    for part, pos in string.gfind(str, pat) do
        nb = nb + 1
        result[nb] = part
        lastPos = pos
        if nb == maxNb then break end
    end
    -- Handle the last field
    if nb ~= maxNb then
        result[nb + 1] = string.sub(str, lastPos)
    end
    return result
end


function ip2pack(Address)
   if Address then
      for key, value in pairs(split(Address, ".")) do
         print(key, value)
      end
   end
end

ip2pack("10.10.10.10")
-- table.foreach(split("/usr/home/pgurumur", "$"), print)
test = split("/usr/home/pgurumur", "/")
print(test[2])
print(#test)
